from itsdangerous import URLSafeTimedSerializer
from itsdangerous import BadData,BadTimeSignature,SignatureExpired
from meiduo_mall import settings
def generic_openid(openid):
    s = URLSafeTimedSerializer("secret-key=settings.SECRET_KEY,expires=3600)")

# 3. 加密数据
    access_token = s.dumps({'openid': openid})
    return access_token.decode()

# # 3. 解密数据
def check_access(token):
    s = URLSafeTimedSerializer("secret-key=settings.SECRET_KEY,expires=3600)")
    try:
        result= s.loads(token)
    except Exception:
        return None
    else: 
        return result.get('openid')